home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / userinfo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  5.8 KB  |  196 lines

  1. unit UserInfo;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, Wincrt, IniFiles, WinTypes, WinProcs, dbtables, Controls
  7. , PasUtils
  8. , Xtension
  9. , Debug;
  10.  
  11. Type
  12.  
  13.   TComponentExtended = class(TComponent)
  14.     cx: TComponentExtensions;
  15.   public
  16.     Constructor Create(aOwner:TComponent); Override;
  17.     Destructor Destroy; Override;
  18.     end;
  19.  
  20.   TUserInfoOptionTypes = (uifUpdateOnLoad,uifUpdateInDesign,uifUpdateOnGet);
  21.   TUserInfoOptions     =  set of TUserInfoOptionTypes;
  22.   TUserInfoStateTypes  = (uifUpdating,uifUpdated);
  23.   TUserInfoState       =  set of TUserInfoStateTypes;
  24.  
  25.   TUserInfo = class(TComponentExtended)
  26.   private
  27.     fOptions: TUserInfoOptions;
  28.     fState: TUserInfoState;
  29.   protected
  30.     function GetState:TUserInfoState;
  31.     procedure SetState(Value:TUserInfoState);
  32.     function GetUpdated: Boolean;
  33.     procedure SetUpdated(Value:Boolean);
  34.     function  CanUpdate:Boolean;
  35.   public
  36.     Constructor Create(aOwner:TComponent); Override;
  37.     procedure Loaded; Override;
  38.     procedure Update;
  39.     function UpdateOK:Boolean; Virtual;
  40.   published
  41.     property Options: TUserInfoOptions read fOptions write fOptions; {what we can do}
  42.     property State: TUserInfoState read fState write SetState stored False; {what we did}
  43.     property Updated: Boolean read GetUpdated write SetUpdated stored false; {if we did}
  44.     end;
  45.  
  46.   TDialogShell = class(TComponentExtended)
  47.   protected
  48.     procedure SetTest(Value:Boolean); virtual;
  49.     function GetTest:Boolean; virtual;
  50.   public
  51.     constructor Create(aOwner:Tcomponent); Override;
  52.     procedure Execute; virtual;
  53.   published
  54.     property Test: Boolean read GetTest write SetTest stored False;
  55.     end;
  56.  
  57. implementation
  58.  
  59. uses Dialogs;
  60.  
  61. {-----------------------------------------------------------------------------------------}
  62. {                                                                                         }
  63. {-----------------------------------------------------------------------------------------}
  64. {-----------------------------------------------------------------------------------------}
  65. { TComponentExtended OBJECT CREATION                                                      }
  66. {-----------------------------------------------------------------------------------------}
  67.  
  68. Constructor TComponentExtended.Create(aOwner:TComponent);
  69. begin
  70.   inherited Create(aOwner);
  71.   cx:=TComponentExtensions.Create(Self);
  72.   if (decCreate in DebugFlags) then
  73.     DebugLog(Owner,'Create '+ClassName+' ('+Owner.Name+':'+Owner.ClassName+')');
  74. end;
  75.  
  76. Destructor TComponentExtended.Destroy;
  77. begin
  78.   if (decDestroy in DebugFlags) then
  79.     DebugLog(Owner,'Destroy '+ClassName);
  80.   cx.Free;
  81.   inherited Destroy;
  82. end;
  83.  
  84. {-----------------------------------------------------------------------------------------}
  85. { TDialogShell  BASE OBJECT  OBJECT CREATION                                              }
  86. {-----------------------------------------------------------------------------------------}
  87.  
  88. Constructor TDialogShell.Create(aOwner:TComponent);
  89. begin
  90.   inherited Create(aOwner);
  91. end;
  92.  
  93. procedure TDialogShell.Execute;
  94. begin
  95. end;
  96.  
  97. procedure TDialogShell.SetTest(Value:Boolean);
  98. begin
  99.   Execute;
  100. end;
  101.  
  102. function TDialogShell.GetTest:Boolean;
  103. begin
  104.   Result:=True;
  105. end;
  106.  
  107.  
  108. {-----------------------------------------------------------------------------------------}
  109. { TUserInfo  BASE OBJECT  OBJECT CREATION                                                 }
  110. {-----------------------------------------------------------------------------------------}
  111.  
  112. Constructor TUserInfo.Create(aOwner:TComponent);
  113. begin
  114.   inherited Create(aOwner);
  115.   Options:=[uifUpdateOnLoad,uifUpdateInDesign,uifUpdateOnGet];
  116. end;
  117.  
  118. procedure TUserInfo.Loaded;
  119. begin
  120.   if (decLoaded in DebugFlags) then
  121.     DebugLog(Owner,'Loaded '+ClassName);
  122.   inherited Loaded;
  123.   if not (csDesigning in ComponentState) then
  124.     if uifUpdateOnLoad in Options then
  125.       Update {actually 'update on load'}
  126.     else
  127.   else
  128.     if uifUpdateInDesign in Options then
  129.       Update; {might be ok to update in design mode as well}
  130. end;
  131.  
  132. procedure TUserInfo.SetState(Value:TUserInfoState);
  133. begin
  134. {basically read-only, showing if prop editor because this proc is ref'd}
  135. {made sensitive to -uifUpdated to allow cx.NilIfSet to unupdate a Userinfo Component}
  136.   if Value=fState-[uifUpdated] then
  137.     fState:=Value;
  138. end;
  139.  
  140. function TUserInfo.GetState:TUserInfoState;
  141. {purpose is to call the update proc when we try to turn the property on.}
  142. begin
  143.   if uifUpdateOnGet in Options then
  144.     Update;
  145.   Result:=fState;
  146. end;
  147.  
  148. function TUserInfo.GetUpdated: Boolean;
  149. begin
  150.   if uifUpdateOnGet in Options then
  151.     Update;
  152.   Result:=uifUpdated in State; {might trigger autoupdate on read. that why we have the proc!}
  153. end;
  154.  
  155. procedure TUserInfo.SetUpdated(Value:Boolean);
  156. begin
  157.   if not Value then
  158.     State:= State - [uifUpdated]
  159.   else
  160.     if not (uifUpdated in State) and Value then
  161.       Update;
  162. end;
  163.  
  164. procedure TUserInfo.Update;
  165. begin
  166.   if ([uifUpdating,uifUpdated]*fState)<>[] then {sets intersect,e.g. state is either updating or updated}
  167.     exit;
  168.   fState:=fState+[uifUpdating]; {MUST access field, changing this property does not change the field!}
  169.   if CanUpdate then
  170.     fState:=fState+[uifUpdated];
  171.   fState:=fState-[uifUpdating];
  172. end;
  173.  
  174. function TUserInfo.CanUpdate:Boolean;
  175. {purpose is to call the update proc when we try to turn the property on.}
  176. begin
  177.  
  178.   if (decUpdate in DebugFlags) then
  179.     with cx do begin
  180.       DebugLog(Owner,'+Update '+Self.ClassName);
  181.       Result:=UpdateOK;
  182.       DebugLog(Owner,'-Update '+Self.ClassName+':= '+BoolString[Result]);
  183.       end
  184.   else
  185.     Result:=UpdateOK {finally we see if it's ok to update now}
  186. end;
  187.  
  188. function TUserInfo.UpdateOK:Boolean; {The 'Ancestor'}
  189. begin
  190.   Result:= True;
  191. end;
  192.  
  193. end.
  194.  
  195.  
  196.